package com.snail.aiChat.functioncalling;

import com.snail.mapper.BizCoursesBaseMapper;
import com.snail.model.dto.CourseBaseDto;
import com.snail.model.dto.CoursePageListDto;
import com.snail.model.pojo.BizCoursesBase;
import com.snail.response.BaseResponse;
import com.snail.response.PageResponse;
import com.snail.response.ResultUtils;
import com.snail.service.BizCourseOutlinesService;
import com.snail.service.BizCoursesBaseService;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Monica
 * @description
 * @date 2025/7/24 14:55
 */
@Component
@RequiredArgsConstructor
public class CourseTools {
    private final BizCourseOutlinesService bizCourseOutlinesService;
    private final BizCoursesBaseService bizCoursesBaseService;
    private final BizCoursesBaseMapper bizCoursesBaseMapper;
    /**
     * 根据课程id查询课程信息
     *
     * @param courseId 课程id
     * @return 课程信息
     */
    @Tool(description = Constant.Tools.QUERY_COURSE_BY_ID)
    public BaseResponse<CourseBaseDto> queryCourseById(@ToolParam(description = Constant.ToolParams.COURSE_ID) Long courseId) {
        return bizCourseOutlinesService.getCourseBaseById(courseId);
    }

    /**
     * 推荐某种类型的课程
     */
    @Tool(description = "根据种类查找相关的课程")
    public BaseResponse<List<CourseBaseDto>> recommendCourseByType(@ToolParam(description = "种类") String type) {
        List<BizCoursesBase> coursesBaseList = bizCoursesBaseMapper.selectList(null);
        List<CourseBaseDto> list = coursesBaseList.stream()
                .filter(course -> course.getTitle().contains(type))
                .map(course -> {
                    CourseBaseDto courseDto = new CourseBaseDto();
                    courseDto.setId(course.getId());
                    courseDto.setTitle(course.getTitle());
                    courseDto.setDescription(course.getDescription());
                    courseDto.setCoverUrl(course.getCoverUrl());
                    return courseDto;
                })
                .toList();
        System.out.println(list);
        return ResultUtils.success(list);
    }
}
